package com.arica.project.mq.service.impl;

import com.arica.framework.dto.MqConsumptionDTO;
import com.arica.project.mq.domain.MqConsumptionDO;
import com.arica.project.mq.mapper.MqConsumptionMapper;
import com.arica.project.mq.service.MqConsumptionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MqConsumptionServiceImpl implements MqConsumptionService {
    @Autowired
    private MqConsumptionMapper mqConsumptionMapper;
    @Override
    public int insert(MqConsumptionDTO mqConsumptionDTO) {
        if(mqConsumptionDTO == null ){
            return 0;
        }
        return mqConsumptionMapper.insert(dtoToDo(mqConsumptionDTO));
    }
    @Override
    public void deleteByKey(String key) {
        if(StringUtils.isBlank(key) ){
            return ;
        }
        mqConsumptionMapper.deleteByKey(key);
    }

    private MqConsumptionDO dtoToDo(MqConsumptionDTO mqConsumptionDTO){
        if(mqConsumptionDTO == null){
            return null;
        }
        MqConsumptionDO mqConsumptionDO = new MqConsumptionDO();
        BeanUtils.copyProperties(mqConsumptionDTO,mqConsumptionDO);
        return mqConsumptionDO;
    }
}
